package wsz.work.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import wsz.work.service.PositionService;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author wsz
 * @date 2022/3/28 16:43
 **/
@Controller
public class PositionController {
    @Autowired
    private PositionService positionService;

    @GetMapping({"/","index"})
    public String indexPage(){
        return "index";
    }

    @ResponseBody
    @GetMapping("/search/{pageNo}/{pageSize}")
    public List<Map<String, Object>> search(@PathVariable("pageNo") int pageNo,
                                            @PathVariable("pageSize") int pageSize, String keyword) throws Exception {
        return positionService.searchPos(keyword, pageNo, pageSize);
    }

    /**
     * 返回默认数据
     * @return
     * @throws Exception
     */
    @ResponseBody
    @GetMapping("/searchDefault/{size}")
    public List<Map<String, Object>> searchDefaultAdd(@PathVariable("size") int size) throws Exception {
        return positionService.searchDefaultAdd(size);
    }

    @GetMapping("/importAll")
    @ResponseBody
    public String importAll(){
        try {
            positionService.importAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }
}
